<?php
/*
 * тут бред продолжается (начало смотреть в маппер lj)
 */
class Service_Post
{
    protected $_postMapper;

    protected $_commentMapper;
    
    protected $_ljSync = true;
    
    public function __construct($postMapper = null, $commentMapper = null)
    {
        if($postMapper === null){
            $this->setPostMapper(new Model_PostsMapper());
        } else {
            $this->setPostMapper($postMapper);
        }
        
        if($commentMapper === null){
            $this->setCommentMapper(new Model_CommentsMapper());
        } else { 
            $this->setCommentMapper($commentMapper);
        }
    }
    
    public static function getInstance()
    {
        return new self();
    }
    
    public function setPostMapper($postMapper)
    {
        $this->_postMapper = $postMapper;   
    }
    
    public function getPostMapper()
    {
        return $this->_postMapper;
    }
    
    public function setCommentMapper($commentMapper)
    {
        $this->_commentMapper = $commentMapper;
    }
    
    public function getCommentMapper()
    {
        return $this->_commentMapper;
    }
    // тут ! хз чо делать
    public function savePost($post)
    {
       $post = $this->_postMapper->save($post);
       if($this->_ljSync){
           $this->setPostMapper(new Model_PostsLiveJournalMapper());
           $this->_postMapper->save($post);
       }
       return $post;
    }
    
    public function findPost($id)
    {
        return $this->_postMapper->find($id);
    }
    
    public function deletePost($post)
    {
        $this->_postMapper->delete($post);
        if($this->_ljSync){
           $this->setPostMapper(new Model_PostsLiveJournalMapper());
           $this->_postMapper->delete($post);
       }
    }
    public function getPostsByPage($page, $blog= null, $itemCountPerPage = 15)
    {
        return $this->_postMapper->getPostsByPage($page, $blog, $itemCountPerPage = 15);
    }
    
    public function getMainPosts()
    {
         return $this->_postMapper->getMainPosts();
    }
    
    public function syncPosts()
    {
        //хотел было писать синхронизацию - расстроился и забил.
    }
}